import request from "./request";

/**
 * 获得验证码
 */
export function getCaptchaApi() {
  return request({
    url: "res/captcha",
    method: "get",
  });
}

/**
 * 检查用户是否存在
 */
export function userIsExistApi(loginId) {
  return request({
    url: `/api/user/userIsExist/${loginId}`,
    method: "get",
  });
}

/**
 * 用户注册
 */
export function addUserApi(regsiterInfo) {
  return request({
    url: "/api/user",
    data: regsiterInfo,
    method: "post",
  });
}

/**
 * 用户登录
 */
export function userLoginApi(loginInfo) {
  return request({
    url: "/api/user/login",
    data: loginInfo,
    method: "post",
  });
}

/**
 * 通过_id获得用户信息
 */
export function getUserByIdApi(id) {
  return request({
    url: `/api/user/${id}`,
    method: "get",
  });
}

/**
 * 保持登录状态
 */
export function getWhoAmIApi() {
  return request({
    url: "/api/user/whoami",
    method: "get",
  });
}

/**
 * 根据 id 修改用户
 */
export function editUser(userId, newUserInfo) {
  return request({
    url: `/api/user/${userId}`,
    method: "PATCH",
    data: newUserInfo,
  });
}

/**
 * 验证用户账号密码是否正确
 */
export function checkPassword(userId, loginPwd) {
  return request({
    url: "/api/user/passwordcheck",
    method: "post",
    data: {
      userId,
      loginPwd,
    },
  });
}
